//
// Created by yhy on 17-7-8.
//

#ifndef UNTITLED2_MYREACTOR_H
#define UNTITLED2_MYREACTOR_H


#include <Poco/Net/SocketReactor.h>
#include <Poco/NotificationCenter.h>
#include <Poco/NObserver.h>
#include "SingletonCheckTimeoutNotification.h"

class MyReactor : public Poco::Net::SocketReactor {
public:
    MyReactor() = default;

    virtual ~MyReactor() = default;
public:
    int getNotifyAllSingletonCheckTimeoutNotification() const;

    void setNotifyAllSingletonCheckTimeoutNotification(int notifyAllSingletonCheckTimeoutNotification);


    void addTimeoutHandler(const Poco::AbstractObserver &observer);;

    void removeTimeoutHandler(const Poco::AbstractObserver &observer);;

protected:
    void onTimeout() override;

    void onIdle() override;

    void onBusy() override;

    bool _needCheckTimeout();

private:
    time_t lastCheckTime = 0;//上次检测时间

    Poco::NotificationCenter nc;    //主题

    //定时发送 SingletonCheckTimeoutNotification 事件。通知每次链接进行一次自检。
    int notifyAllSingletonCheckTimeoutNotification = 360;
};


#endif //UNTITLED2_MYREACTOR_H
